<style type="text/css" title="currentStyle">
	@import "../media/css/demo_page.css";
	@import "../media/css/demo_table_jui.css";
	@import "../examples_support/themes/smoothness/jquery-ui-1.8.4.custom.css";
	@import "media/css/TableTools_JUI.css";
</style>
<script type="text/javascript" charset="utf-8" src="../media/js/jquery.dataTables.js"></script>
<script type="text/javascript" charset="utf-8" src="media/js/ZeroClipboard.js"></script>
<script type="text/javascript" charset="utf-8" src="media/js/TableTools.js"></script>
<script type="text/javascript" charset="utf-8">
	$(document).ready( function () {
		$('#example').dataTable( {
			"bJQueryUI": true,
			"sPaginationType": "full_numbers",
			"sDom": 'Tlfrtip',	
			"oTableTools": {
				"aButtons": [
					"copy", "csv", "xls", "pdf", "print",
					{
						"sExtends":    "collection",
						"sButtonText": "Save",
						"aButtons":    [ "csv", "xls", "pdf" ]
					}
				]
			}
		} );
	} );
</script>

<script language="javascript">
var ajax1=new sack();


function checkUser(tableName,condStr,val,id)
{
	
}

function resultCount()
{
  if(ajax1.response > 0 )
  {
  	alert("Data Updated Successfully");
	location.href = '?ch=viewClient';
  }
  else
  {
	  alert("Data not Updated");
  }
	
}
function changeSts(id,span,cid)
{
	if(document.getElementById(id).checked)
		status = 1;
	else
		status = 0;
	qry = "update tb_userinfo set ui_accessFlag = "+status+" where ui_clientId = "+cid;		
	ajax1.requestFile = 'ajax_server.php?ajaxQry='+qry;
//	alert(ajax1.requestFile);
	ajax1.onCompletion = function(){resultClientStatus(span,id)};
	ajax1.runAJAX();
	
}
function resultClientStatus(span,id)
{
  //alert(ajax1.response)	
  if(ajax1.response == 1)
  {
	 alert("Status Updated Successfully.");
	 if(document.getElementById(id).checked) 
	  	document.getElementById(span).innerHTML = 'Deactive';
	 else 
		document.getElementById(span).innerHTML = 'Active';
	
	window.location.href = "?ch=viewClient";
  }
  else
  {
	  alert("Status Not Updated. Please try later.");
	  window.location.href = "?ch=viewClient";
  }
	
}
function editSMSCount(cid,val)
{
	t = prompt("Please enter SMS Credits",val);
	if(t)
	{
		qry = "update tb_clientinfo set ci_smsCount = "+t+" where ci_id = "+cid;		
		ajax1.requestFile = 'ajax_server.php?ajaxQry='+qry;
		//alert(ajax1.requestFile);
		ajax1.onCompletion = function(){resultCount()};
		ajax1.runAJAX();
	}
	else
	{
		//alert("Please enter valid integer");
		//editSMSCount(cid,val);
	}
}
function redirectUser(uid,cid,rid)
{
	document.frmRedirectUser.txtClientId.value = cid;
	document.frmRedirectUser.ResellID.value = rid;
	document.frmRedirectUser.txtUserId.value = uid;
	document.frmRedirectUser.action = "ajax_server.php";
	document.frmRedirectUser.submit();
}
function callDiffClient(clientType)
{
	document.frmClientType.txtClientType.value = clientType;
	document.frmClientType.submit();
}
function funEditUser(uid,act)
{
	document.frmSubmit.txtClientId.value = uid;
	document.frmSubmit.action = act;
	document.frmSubmit.submit();
}
</script>
<div align="left" class="listofusers">&nbsp;<a href="#" onclick="location.href='?ch=addClient';">Add New Client</a></div>
<table cellpadding="0" cellspacing="0" border="0" class="gridform_final" id="example">      
	<thead>
    <tr>
		<th width="5%">#</th>
        <th width="20%">Client Name</th>
        <th width="10%">Username</th>
        <th width="10%">Land Line</th> 
        <th width="10%">Mobile </th>
        <th width="10%">Email 1</th>
<!--        <th width="10%">Email 2</th>
-->        <th width="10%">Status</th>
        <th width="7%">View</th>
        <th width="10%">Avail. SMS</th>
        <th width="7%">Edit</th>
   </tr>
   </thead>
   <tbody>
   <?php
	$sql = "SELECT * FROM tb_clientinfo WHERE ci_clientType='Client' AND ci_clientId=".$_SESSION[clientID]." ORDER BY ci_clientName ASC";
	$rows = $db->query($sql);

   if($db->affected_rows > 0)
   {
   $i = 1;
   	while ($record = $db->fetch_array($rows)) 
	{
		$getUserACC = "SELECT ui_id,ui_username FROM tb_userinfo WHERE ui_isAdmin = 1 AND ui_accessFlag = 1 AND ui_clientId = ".$record[ci_id];
		$rowUserAcc = $db->query($getUserACC);
		$totUser = $db->affected_rows;
		if($totUser > 0)
		{
			$fetUseAcc = $db->fetch_array($rowUserAcc);
			$userName = '<a href="#" onclick="redirectUser('.$fetUseAcc[ui_id].','.$record[ci_id].','.$_SESSION[clientID].')";>'.ucfirst($fetUseAcc[ui_username]).'</a>';
		}
		else $userName = "Not Created";
	?>
    <tr>
		<td><?php echo $i;?></td>
        <td><?php echo ucfirst($record[ci_clientName]);?></td>
        <td><?php echo $userName;?></td>
        <td><?php echo $record[ci_phoneNumber];?> </td>
        <td><?php echo $record[ci_mobileNumer];?> </td>
        <td><a href="mailto:<?php echo $record[ci_email1];?>"><?php echo $record[ci_email1];?></a></td>
        <!--<td><a href="mailto:<?php echo $record[ci_email2];?>"><?php echo $record[ci_email2];?></a></td>-->
        <td>
		<input type="checkbox" name="chkUsrStatus<?php echo $i;?>" id="chkUsrStatus<?php echo $i;?>" <?php if($totUser > 0) {?> checked="checked" <?php } ?> onclick="changeSts(this.id,'stsId<?php echo $i;?>','<?php echo $record[ci_id];?>')"/>
            <span id="stsId<?php echo $i;?>"><?php if($totUser > 0) echo "Deactive"; else echo "Active"; ?></span>
		</td>
        <td><img src="../../images/view.gif" style="cursor:pointer;" width="45" height="16" border="0"  onclick="funEditUser('<?php echo $record[ci_id];?>','?ch=viewClientDevice')" /></td>
        <td><?php echo $record[ci_smsCount];?> - <a href="#" onclick="editSMSCount('<?php echo $record[ci_id];?>','<?php echo $record[ci_smsCount];?>')">Edit</a></td>        
        <td><img src="../../images/edit.gif" style="cursor:pointer;" width="45" height="16" border="0" onclick="funEditUser('<?php echo $record[ci_id];?>','?ch=addClient')" /></td>
   </tr>
   <?php
   	$i++;
   	//$avail = 0;
   //}
	}
	}
   ?>
	</tbody>
</table>
<form name="frmSubmit" id="frmSubmit" method="post">
	<input type="hidden" name="txtClientId" id="txtClientId" />
</form>
<form name="frmClientType" id="frmClientType" method="post">
	<input type="hidden" name="txtClientType" id="txtClientType" />
</form>
<form name="frmRedirectUser" id="frmRedirectUser" method="post">
	<input type="hidden" name="txtUserId" id="txtUserId" />
    <input type="hidden" name="txtClientId" id="txtClientId" />
    <input type="hidden" name="ResellID" id="ResellID" />
</form>